package top.xcxdl.rural;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.coremedia.iso.IsoFile;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.bind.annotation.ResponseBody;
import top.xcxdl.rural.config.initexception.BusinessException;
import top.xcxdl.rural.config.initexception.ErrorEnum;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Ding
 * @create 2022/5/6 21:13
 */
@SpringBootTest
public class myT {

    @Test
    public void test() {
        String str = "[{\"label\": \"A\", \"content\": \"adhasiudhasidhashdas\"}, {\"label\": \"B\", \"content\": \"adhasiudhasidhashdas\"}, {\"label\": \"C\", \"content\": \"adhasiudhasidhashdas\"}, {\"label\": \"A\", \"content\": \"adhasiudhasidhashdas\"}, {\"label\": \"B\", \"content\": \"adhasiudhasidhashdas\"}, {\"label\": \"C\", \"content\": \"adhasiudhasidhashdas\"}, {\"label\": \"A\", \"content\": \"adhasiudhasidhashdas\"}, {\"label\": \"B\", \"content\": \"adhasiudhasidhashdas\"}, {\"label\": \"C\", \"content\": \"adhasiudhasidhashdas\"}]";
        System.err.println(JSONArray.parseObject(str, JSONArray.class));
    }

    @Test
    public void t(){
        //定义一个文件路径
        String filePath = "D:\\_APP\\WeChat\\Files\\WeChat Files\\wxid_amqujs58q12c22\\FileStorage\\File\\2022-04\\animation\\img";
        //new这个file对象
        File file = new File(filePath);
        //获取该目录下的所有文件
        File[] files = file.listFiles();
        //遍历files
        for (int i = 0; i < files.length; i++) {
            files[i].renameTo(new File(filePath + "\\" +(i+1) + ".jpg"));
        }
    }


    @Test
    public void TT() throws ParseException {
        DateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
        String beginTime = "2018-12-21";
        Date beginDate = dft.parse(beginTime);
        Date nowDate = new Date();

        long between = (nowDate.getTime() - beginDate.getTime()) / 1000;//除以1000是为了转换成秒

        long day = between / (24 * 3600);

        System.err.println(day);
    }

    @Test
    public void tT(){
        File file = new File("https://ruralbucket.oss-accelerate.aliyuncs.com/resource/ce0778df0ccf4cdaace855784154f5c6.mp4");
        IsoFile isoFile = null;
        try {
            isoFile = new IsoFile(file.getPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
        long lengthInSeconds =
                    isoFile.getMovieBox().getMovieHeaderBox().getDuration() /
                            isoFile.getMovieBox().getMovieHeaderBox().getTimescale();
//            file.delete();
            System.err.println("视频时长：" + lengthInSeconds);
            System.err.println("视频时长：" + lengthInSeconds);
            System.err.println("视频时长：" + lengthInSeconds);
            System.err.println("视频时长：" + lengthInSeconds);
    }
}
